package com.ruoyi.system.service.waterService.waterServiceImpl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.waterEnity.OrderEntity;
import com.ruoyi.system.domain.waterEnity.OrderItemEntity;
import com.ruoyi.system.mapper.waterMapper.OrderMapper;
import com.ruoyi.system.service.waterService.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
   @Autowired
    private OrderMapper orderMapper;
    @Override
    public List<OrderEntity> selectOrderList() {
        return orderMapper.selectOrderList();
    }

    @Override
    public String updateOrderById(String id) {
        return orderMapper.updateOrderById(id);
    }

    @Override
    public List<OrderItemEntity> selectOrderItemByOrder_id(String id) {
        return orderMapper.selectOrderItemByOrder_id(id);
    }

    @Override
    public OrderEntity selectOrderByOrder_id(String order_id) {
        return orderMapper.selectOrderByOrder_id(order_id);
    }

    @Override
    @Transactional
    public int deleteOrder(String orderids) {
        Long[] orderIds = Convert.toLongArray(orderids);
        int orderNum = orderMapper.deleteOrder(orderIds);
        if (orderNum > 0) {
            int normNum = orderMapper.deleteOrderItem(orderIds);
            if (normNum >= 0) {
                return 1;
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }
    @Override
    public List<OrderEntity> selectOrder(String order_id, String pay_state, String state) {
        String flag= order_id+ pay_state + state + state ;
        List<OrderEntity> list = null;
        if (StringUtils.isEmpty(flag)){
            list = orderMapper.selectOrderList();
        }else if (StringUtils.isNotEmpty(order_id)){
            list = orderMapper.selectOrderByOrder_id2(order_id);
        }else if (StringUtils.isNotEmpty(pay_state)){
            list = orderMapper.selectOrderByPay_state(pay_state);
        }else if (StringUtils.isNotEmpty(state)){
            list = orderMapper.selectOrderByState(state);
        }
        else{
            list = orderMapper.selectOrderList();
        }
        return list;
    }

}
